Obafemi Emmanuel

Installing PHP (Local Server Setup with XAMPP/WAMP)

Published 3 weeks ago

Introduction

PHP (Hypertext Preprocessor) is a popular scripting language used for web development. To develop and test PHP applications locally, we need a local server environment. XAMPP and WAMP are two widely used solutions that provide an easy-to-use local development environment.

In this guide, we will walk you through the process of installing PHP using XAMPP and WAMP, configuring them, and running a simple PHP script.


1. Understanding Local Servers: XAMPP vs. WAMP

A local server environment allows developers to run and test PHP applications on their computer without requiring an internet connection. The two most popular options are:

  • XAMPP: A cross-platform software package that includes Apache, MariaDB, PHP, and Perl. Works on Windows, macOS, and Linux.
  • WAMP: A Windows-based software stack that includes Apache, MySQL, and PHP. It is designed specifically for Windows users.

Key Differences


2. Installing XAMPP

Step 1: Download XAMPP

  1. Visit the official XAMPP website.
  2. Download the latest version for your operating system (Windows, macOS, or Linux).

Step 2: Install XAMPP

  1. Run the downloaded installer file.
  2. Follow the installation wizard:
  • Select components (default selection is recommended).
  • Choose the installation directory (e.g., C:\xampp).
  • Complete the installation.
  1. Launch XAMPP Control Panel after installation.

Step 3: Start Apache and MySQL

  1. Open the XAMPP Control Panel.
  2. Click Start next to Apache and MySQL.
  3. If you see green indicators, the services are running.

Step 4: Verify Installation

  1. Open a browser and type http://localhost.
  2. You should see the XAMPP dashboard.
  3. To check PHP, create a file test.php in C:\xampp\htdocs\ with the following content:
<?php
phpinfo();
?>
  1. Open http://localhost/test.php in a browser. If PHP information is displayed, the setup is successful.

3. Installing WAMP

Step 1: Download WAMP

  1. Visit the official WAMP website.
  2. Download the appropriate version (32-bit or 64-bit) based on your system.

Step 2: Install WAMP

  1. Run the downloaded installer.
  2. Follow the installation wizard:
  • Select components (default selection is recommended).
  • Choose the installation directory (e.g., C:\wamp64).
  • Complete the installation.

Step 3: Start WAMP Server

  1. Launch WAMP from the Start Menu or Desktop shortcut.
  2. If the WAMP icon in the system tray is green, it means all services (Apache, MySQL, PHP) are running.
  3. If the icon is orange, some services may not be running. Restart WAMP or check for port conflicts.

Step 4: Verify Installation

  1. Open a browser and type http://localhost.
  2. You should see the WAMP homepage.
  3. Create a file test.php inside C:\wamp64\www\ with the following content:
<?php
phpinfo();
?>
  1. Open http://localhost/test.php in a browser. If PHP information is displayed, the setup is successful.

4. Configuring PHP in XAMPP/WAMP

Changing PHP Version (For Multiple Versions)

  • In XAMPP: Switch PHP versions via the control panel.
  • In WAMP: Click the WAMP icon > PHP > Version and select the desired version.

Changing PHP Configuration (php.ini)

  1. Locate php.ini:
  • XAMPP: C:\xampp\php\php.ini
  • WAMP: C:\wamp64\bin\php\phpX.X.X\php.ini
  1. Open php.ini in a text editor.
  2. Modify necessary settings, e.g., increase file upload size:
upload_max_filesize = 64M
post_max_size = 64M
  1. Restart Apache after making changes.

5. Running PHP Scripts

  1. Create a new file hello.php in the respective htdocs or www folder:
<?php
echo "Hello, World!";
?>
  1. Open http://localhost/hello.php in a browser.
  2. You should see Hello, World! displayed.

6. Common Issues and Troubleshooting

Port Conflict with Apache

  • If Apache doesn’t start, another application may be using port 80.
  • Change Apache’s port:
  1. Open httpd.conf (located in C:\xampp\apache\conf\ or C:\wamp64\bin\apache\apacheX.X.X\conf\).
  2. Find Listen 80 and change it to Listen 8080.
  3. Restart Apache and access http://localhost:8080.

MySQL Not Starting

  • Ensure MySQL is not running from another service.
  • Change the MySQL port from 3306 to 3307 in the my.ini file.

Missing vcruntime140.dll Error (For WAMP)

Conclusion

Setting up PHP using XAMPP or WAMP is straightforward and provides a complete local development environment. XAMPP is cross-platform, while WAMP is tailored for Windows users. By following this guide, you can install, configure, and run PHP applications locally with ease.

With your local server set up, you’re ready to start developing dynamic PHP applications efficiently!


Leave a Comment


Choose Colour